package com.yn.front.driver;


import com.yn.common.model.zy.TCarFleetManageDO;
import com.yn.common.page.BasePage;
import com.yn.common.request.sc.CarFleetManageRequest;
import com.yn.common.request.sc.CarManageRequest;
import com.yn.common.request.sc.PageParamRequest;
import com.yn.common.response.driver.DriverFleetDetailResponse;

import com.yn.common.response.driver.FleetManageDetailResponse;
import com.yn.common.response.sc.BaseResult;
import com.yn.common.vo.CarFleetPageDrVO;
import com.yn.service.zy.TCarFleetManageService;

import com.yn.service.zy.model.dto.TCarManageDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

@RestController
@RequestMapping("/tcarfleetmanage/driver")
@Api(tags = "车队相关接口——司机端")
public class CarFleetController {
    @Autowired
    private TCarFleetManageService tCarFleetManageService;

    /**
     * 添加车队
     * @param request
     */
    @PostMapping("/save")
    @ApiOperation(value = "添加车队")
    public BaseResult<String> save(@RequestBody @Validated CarFleetManageRequest request){
        tCarFleetManageService.saveFleet(request);
        return BaseResult.success();
    }

    /**
     * 根据id查询车队信息——用于编辑回显
     * */
    @ApiOperation("根据id查询车队信息")
    @GetMapping("/info")
    public BaseResult<TCarFleetManageDO> getInfo(@ApiParam("车辆id") @RequestParam @NotNull Integer id) {
        return BaseResult.success(tCarFleetManageService.selectMyFleetInfoById(id));
    }
    /**
     * 司机端分页获取车队列表
     * @param keyWords
     * @param carFleetName
     * @param pageParamRequest
     * @return
     */
    @ApiOperation("分页查询车队列表")
    @GetMapping("/list-page")
    public BaseResult<BasePage<CarFleetPageDrVO>> listPage(@ApiParam("车队名称") @RequestParam(required = false)
                                                               String carFleetName,
                                                           @ApiParam("关键字") @RequestParam(required = false)
                                                               String keyWords,
                                                           PageParamRequest pageParamRequest){

        return BaseResult.success((BasePage.restPage(tCarFleetManageService.drListPage(carFleetName,keyWords,pageParamRequest))));
    }

    /**
     * 司机端查看某个车队的详情——包括车队的司机，
     * */
    @GetMapping("/detail/info")
    @ApiOperation("获取某个车队详情")
    public BaseResult<FleetManageDetailResponse> detailInfo(@ApiParam("车队id") @RequestParam @NotNull Integer id) {

        return BaseResult.success(tCarFleetManageService.getFleetDetailInfo(id));
    }

    /**
     * 为某个车队添加车辆信息
     *传过来的id时车队id
     * */
    @PostMapping("/save/car")
    @ApiOperation(value = "为车队添加车辆信息——(丢弃)")
    public BaseResult<String> saveCar(@RequestBody @Validated CarManageRequest request,
                                      @RequestParam(value = "id",required = true)
                                      Integer id){
        tCarFleetManageService.saveCar(request,id);
        return BaseResult.success();
    }


}
